001 /*
002 * Copyright (c) 2005 Stephen J. McConnell
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
013 * implied.
014 *
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019 package net.dpml.metro.tools;
020
021 import net.dpml.state.DefaultTransition;
022 import net.dpml.state.DefaultOperation;
023
024 import org.apache.tools.ant.BuildException;
025
026 /**
027 * Utility datatype supporting a Transition instance construction.
028 *
029 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a>
030 * @version 1.1.0
031 */
032 public class TransitionDataType
033 {
034 private String m_name;
035 private String m_target;
036 private OperationDataType m_operation;
037
038 /**
039 * Set the operation name.
040 * @param name the operation name
041 */
042 public void setName( final String name )
043 {
044 if( null == name )
045 {
046 throw new NullPointerException( "name" );
047 }
048 m_name = name;
049 }
050
051 /**
052 * Set the transition target.
053 * @param target the relative address of the target state
054 */
055 public void setTarget( final String target )
056 {
057 if( null == target )
058 {
059 throw new NullPointerException( "target" );
060 }
061 m_target = target;
062 }
063
064 /**
065 * Add an operation to the transition.
066 * @return the operation datatype
067 */
068 public OperationDataType createOperation()
069 {
070 if( null != m_operation )
071 {
072 final String error =
073 "Transition is attempting to declare more than one operation.";
074 throw new IllegalStateException( error );
075 }
076 m_operation = new OperationDataType();
077 return m_operation;
078 }
079
080 DefaultTransition getTransition()
081 {
082 String name = getName();
083 String target = getTargetName();
084 if( null == m_operation )
085 {
086 return new DefaultTransition( name, target, null );
087 }
088 else
089 {
090 DefaultOperation operation = m_operation.getOperation();
091 return new DefaultTransition( name, target, operation );
092 }
093 }
094
095 String getName()
096 {
097 if( null != m_name )
098 {
099 return m_name;
100 }
101 else
102 {
103 throw new BuildException( "Missing transition name attribute." );
104 }
105 }
106
107 String getTargetName()
108 {
109 if( null != m_target )
110 {
111 return m_target;
112 }
113 else
114 {
115 throw new BuildException( "Missing transition target attribute." );
116 }
117 }
118 }